package com.yxd.server;

import com.yxd.bootstrap.Constants;
import com.yxd.logging.SysLogger;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by Administrator on 2016/6/15.
 */
public class HttpServer {

    private boolean shutdown = false;

    public void await() {
        ServerSocket serverSocket = null;
        int port = Constants.PORT;
        try {
            serverSocket = new ServerSocket(port);
        } catch (Exception e) {
            e.printStackTrace();

            System.exit(1);
        }

        SysLogger.info("httpServer is listening at port:" + port);
        while (!shutdown) {
            try {
                Socket socket = serverSocket.accept();
                HttpWork work = new HttpWork(socket);
                work.doWork();
//                shutdown = request.getUri() == HttpServer.SHUTDOWN_COMMAND;
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
        }
        try {
            serverSocket.close();
        } catch (Exception e) {
            e.printStackTrace();

        }

    }

}
